<?php

namespace app\admin\model;

use think\Model;


class OrderReturn extends Model
{

    

    

    // 表名
    protected $name = 'order_return';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        's_load_time_text',
        'e_load_time_text',
        'time_text',
        'load_status_text',
        'lay_status_text',
        'status_text',
        'j_time_text',
        'spay_status_text',
        'jpay_status_text',
        'pay_time_text',
        'often_status_text'
    ];
    

    
    public function getLoadStatusList()
    {
        return ['1' => __('Load_status 1'), '2' => __('Load_status 2')];
    }

    public function getLayStatusList()
    {
        return ['1' => __('Lay_status 1'), '2' => __('Lay_status 2'), '3' => __('Lay_status 3'), '4' => __('Lay_status 4')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6'), '9' => __('Status 9')];
    }

    public function getSpayStatusList()
    {
        return ['1' => __('Spay_status 1'), '2' => __('Spay_status 2'), '3' => __('Spay_status 3')];
    }

    public function getJpayStatusList()
    {
        return ['1' => __('Jpay_status 1'), '2' => __('Jpay_status 2'), '3' => __('Jpay_status 3')];
    }

    public function getOftenStatusList()
    {
        return ['0' => __('Often_status 0'), '1' => __('Often_status 1')];
    }


    public function getSLoadTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['s_load_time']) ? $data['s_load_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getELoadTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['e_load_time']) ? $data['e_load_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getLoadStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['load_status']) ? $data['load_status'] : '');
        $list = $this->getLoadStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['lay_status']) ? $data['lay_status'] : '');
        $list = $this->getLayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['j_time']) ? $data['j_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSpayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['spay_status']) ? $data['spay_status'] : '');
        $list = $this->getSpayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJpayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jpay_status']) ? $data['jpay_status'] : '');
        $list = $this->getJpayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOftenStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['often_status']) ? $data['often_status'] : '');
        $list = $this->getOftenStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setSLoadTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setELoadTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setJTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function car2()
    {
        return $this->belongsTo('Car2', 'car2_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'j_uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function addr()
    {
        return $this->belongsTo('Addr', 's_addr_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
